package com.google.code.sms.controller;

import com.google.code.sms.service.SettingsService;
import com.google.code.sms.Logger;
import org.springframework.web.servlet.*;
import org.springframework.web.servlet.mvc.*;

import javax.servlet.http.*;
import java.util.*;

/**
 * Controller for the help page.
 *
 * @author Sindre Mehus
 */
public class HelpController extends ParameterizableViewController {

    private SettingsService settingsService;

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Map<String, Object> map = new HashMap<>();

        map.put("localVersion", settingsService.getVersion());
        map.put("logEntries", Logger.getLatestLogEntries());
        map.put("logFile", Logger.getLogFile());

        ModelAndView result = super.handleRequestInternal(request, response);
        result.addObject("model", map);
        return result;
    }

    public void setSettingsService(SettingsService settingsService) {
        this.settingsService = settingsService;
    }
}
